import request from '@/utils/request';

export interface PurchasePlan {
  planId: number;
  name: string | null;
  type: number | null;
  startTime: string | null; // datetime
  endTime: string | null; // datetime
  description: string | null;
  department: string | null;
  plannerName: string | null;
  createTime: string | null; // datetime
  updateTime: string | null; // datetime
  budget: number | null; // decimal(10,2)
  status: number | null;
}
export interface FormItemConfig {
  type: 'input' | 'datetime' | 'select'; // 扩展你需要的类型
  label: string;
  prop: keyof PurchasePlan; // 关键修改：确保 prop 只能是 PurchasePlanModel 的键
  placeholder?: string;
  inputType?: HTMLInputElement['type'];
  options?: Array<{label: string, value: any}>;
}

export interface PurchasePlanListResponse{
  current: number,
  total: number,
  pages: number,
  size: number,
  records: PurchasePlan[]
}

export interface PurchasePlanModel {
  IsUpdate:boolean|null;
  planId: number|null;

  name: string | null;
  type: number | null;

  description: string | null;  
  department: string | null;
  plannerName: string | null;

  budget: number | null; // decimal(10,2)
  status: number | null; 

  startTime: string | null; // datetime
  endTime: string | null; // datetime
}


export const planApi = {
  getPlanList:(params:any)=>{
    return request<PurchasePlanListResponse>({
      method: 'GET',
      url: `/procedure/purchasePlans`,
      params: params
    })
    //request.get('/product', { params }) 方法别名风格
  },

  addPlan: (data: PurchasePlanModel) => {
    return request<String>({
      method: 'POST',
      url: `/procedure/purchasePlans`,
      data: data
    })
  },

  updatePlan: (id: number, data: PurchasePlanModel) => {
    return request<String>({
      method: 'PUT',
      url: `/procedure/purchasePlans/${id}`,
      data: data
    })
  },

  deletePlan: (id: number) => {
    return request<String>({
      method: 'DELETE',
      url: `/procedure/purchasePlans/${id}`,
    })
  },
}


export const planTypeMap = {
  1: '年度计划',
  2: '季度计划',
  3: '临时计划'
} as const
export const statusMap = {
  0: '申请被驳回',
  1: '待审批',
  2: '审批通过',
  3: '待招标',
  4: '招标中',
  5: '定标完成',
  6: '合同签订',
  7: '设备运输中',
  8: '设备到货',
  9: '已完成',
} as const;

export const getPlanTypeLabel = (value: any): string => {
  return planTypeMap[value as keyof typeof planTypeMap] || '未知类型'
}
export const getStatusLabel = (value: number): string => {
  return statusMap[value as keyof typeof statusMap] || '未知状态';
};
